package com.bicon.botu.finance.wallet.rpc;

import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import com.bicon.botu.finance.wallet.entity.WalletDetail;
import com.bicon.botu.finance.wallet.service.WalletDetailService;
import com.bicon.botu.finance.wallet.service.WalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * 钱包rpc
 *
 * @author tandk
 * @date 2017/9/15 0015 上午 9:49
 */
@RestController
@RequestMapping("/V2.0.0/rpc/wallet")
public class WalletRpcV2 extends BaseController {


    @Autowired
    private WalletService walletService;

    @Autowired
    private WalletDetailService walletDetailService;

    /**
     * 增加余额并保存账户记录
     *
     * @param userId        用户id
     * @param money         金额
     * @param subjects      主题分类 0.收入，1.支出，2.充值，3.提现
     * @param financialType 支付类型 0:余额，1：支付宝，2：微信，3：银联
     * @param subjectChild  主题子项 0.转账；1.拼手气红包；2.普通红包；3.个人对个人红包
     * @param remark        备注
     * @return
     */
    @RequestMapping(value = "/addIncome", method = RequestMethod.POST)
    public BaseResult addIncome(@RequestParam(value = "userId") String userId, @RequestParam(value = "money") double money,
                                @RequestParam(value = "subjects") String subjects, @RequestParam(value = "financialType") String financialType,
                                @RequestParam(value = "subjectChild") String subjectChild, @RequestParam(value = "remark") String remark,
                                @RequestParam(value = "appId") String appId, @RequestParam(value = "module") String module, @RequestParam(value = "business") String business) {
        return walletService.addBalanceV2(appId, module, business, userId, money, subjects, financialType, subjectChild, remark);
    }


    /**
     * 校验支付信息并支付
     *
     * @param userId   用户id
     * @param password 用户密码
     * @param payType  支付类型 0:余额，1：支付宝，2：微信，3：银联
     * @param password 金额
     * @return
     */
    @RequestMapping(value = "checkPayInfo", method = RequestMethod.POST)
    public BaseResult checkPayInfo(@RequestParam(value = "userId") String userId, @RequestParam(value = "password") String password,
                                   @RequestParam(value = "payType") String payType, @RequestParam(value = "money") double money,
                                   @RequestParam(value = "subject") String subject, @RequestParam(value = "subjectChild") String subjectChild,
                                   @RequestParam(value = "appId") String appId, @RequestParam(value = "module") String module, @RequestParam(value = "business") String business) {
        return walletService.checkPayInfo(appId, module, business, userId, payType, password, money, "BOTU", subject, subjectChild);

    }

    /**
     * 封装账户流水信息
     *
     * @param type         类型 0:余额，1：支付宝，2：微信，3：银联
     * @param userId       用户id
     * @param walletId     钱包id
     * @param money        金额
     * @param subject      一级科目  0.收入，1.支出，2.充值，3.提现
     * @param subjectChild 二级科目  0.转账；1.拼手气红包；2.普通红包；3.个人对个人红包
     * @param orderNo      订单号
     * @param payOrderNo   支付订单号
     * @param state        状态 0:交易中 1:交易成功 2:交易失败 3交易取消 4待收款
     * @param financialId  金融账户
     * @param payInfo      支付信息
     * @param remark       备注
     * @return
     */
    @RequestMapping(value = "/addWalletDetail", method = RequestMethod.POST)
    public BaseResult addWalletDetail(String appId, String module, String business, String type, String userId, String walletId, BigDecimal money, String subject, String subjectChild, String orderNo, String payOrderNo, String state, String financialId, String payInfo, String remark) {

        WalletDetail walletDetail = walletService.addWalletDetail(appId, module, business, type, userId, walletId, money, subject, subjectChild, orderNo, payOrderNo, state, financialId, payInfo, remark);
        if (null == walletDetail) {
            return sendResult500();
        }
        return sendResult200();
    }

    /**
     * 赞赏
     *
     * @param fromUserId 赞赏者
     * @param money      赞赏金额
     * @param toUserId   被赞赏者
     * @param payPwd     支付密码
     * @param remark     备注
     * @param payType    支付类型 类型 0:余额，1：支付宝，2：微信，3：银联
     * @param code       BOTU
     * @return
     */
    @RequestMapping(value = "/gratuity", method = RequestMethod.POST)
    public BaseResult gratuity(String module, String business, String fromUserId, double money, String toUserId, String payPwd, String remark, String payType, String code) {
        return walletService.gratuity(module, business, fromUserId, money, toUserId, payPwd, remark, payType, code);
    }

    /**
     * 订单支付
     *
     * @param fromUserId 发送人用户id
     * @param money      金额
     * @param toUserId   接收商铺id
     * @param payPwd     支付密码
     * @param remark     备注
     * @param payType    支付类型 类型 0:余额，1：支付宝，2：微信，3：银联
     * @param code       BOTU
     * @return
     */

    @RequestMapping(value = "/gratuity1", method = RequestMethod.POST)
    public BaseResult gratuity1(String module, String business, String fromUserId, double money, String toUserId, String payPwd, String remark, String payType, String code) {
        return walletService.gratuity1(module, business, fromUserId, money, toUserId, payPwd, remark, payType, code);
    }


}
